﻿package {
	import flash.display.*;
	import flash.events.*;
	/*
	*classe de gestion des interaction carte
	*/
	public class CarteAJouer extends MovieClip
	{
		static const RETOURNEX:int = 300;
		static const RETOURNEY:int = 200;
		static const ESTJOUEEX:int = 0;
		static const ESTJOUEEY:int = 0;
		public var carte : MovieClip;
		public var numero:String;
		public var couleur:String;
		public var jouable:Boolean;
		static var position:int=300;
		static var plateau:Carte;
		public var traitementMsg:TraitementMessage;
		public var jeuCarte:Carte;
		public function CarteAJouer(sclass:Class,snumero:String,scouleur:String,traitementMsgSrc:TraitementMessage,crt:Carte)
		{
			this.jeuCarte = crt;
			this.traitementMsg=traitementMsgSrc
			carte = new sclass;
			addChild(carte);
			numero = snumero;
			couleur = scouleur;
			jouable = false;
		}
		public static function setPlateau(plateau:Carte):void
		{
			plateau=plateau;
		}
		public function debug_affiche()
		{
			trace("debug :: "+this.numero+" de "+this.couleur);
		}
		public function setJouable(bool:Boolean):void
		{
			this.jouable=bool;
		}
		public function estSurvolee(event:MouseEvent):void
		{
			if (jeuCarte.statusJoueur!="attente")
			{
				if (jouable)
				{
					this.y=this.y-10;
					this.removeEventListener(flash.events.MouseEvent.MOUSE_OVER, estSurvolee);
					this.addEventListener(flash.events.MouseEvent.MOUSE_OUT, estPlusSurvolee);
					this.addEventListener(flash.events.MouseEvent.CLICK, estJouee);
				}
			}
		}
		public function estPlusSurvolee(event:MouseEvent):void
		{
			if (jouable)
			{
				this.y=this.y+10;
				//trace("n'est plus survolée");
				this.removeEventListener(flash.events.MouseEvent.MOUSE_OUT, estPlusSurvolee);
				this.addEventListener(flash.events.MouseEvent.MOUSE_OVER, estSurvolee);
			}
		}
		public function estJouee(event:MouseEvent):void
		{
			
			//this.x=ESTJOUEEX;
			//this.y=ESTJOUEEY;
			//this.x = 0;
			//this.y = 0;
			this.jeuCarte.poserCarte(this);
			traitementMsg.envoyerCoupJoué(this);
			this.removeEventListener(flash.events.MouseEvent.MOUSE_OUT, estPlusSurvolee);
			this.removeEventListener(flash.events.MouseEvent.CLICK, estJouee);
			
			
			trace("carte jouée");
		}
		public function estCliquee(event:MouseEvent):void
		{
			trace("simple clic");
		}		
		public function sourisAppuyee(event:MouseEvent):void
		{
			this.startDrag();
			
		}
		public function sourisRelachee(event:MouseEvent):void
		{
			this.stopDrag();

		}	
		public function estRetournee(cont:DisplayObjectContainer):void
		{
			this.y=RETOURNEY;
			this.x=RETOURNEX;
			cont.addChild(this);
			position=position+15;
			this.addEventListener(flash.events.MouseEvent.MOUSE_OVER, estSurvolee);
		}
		public function estDistribuee(cont:DisplayObjectContainer):void
		{
			trace("estDistribuee : "+this.numero+" de "+this.couleur);
			this.y=400;
			this.x=position;
			cont.addChild(this);
			position=position+15;
			this.addEventListener(flash.events.MouseEvent.MOUSE_OVER, estSurvolee);
			//this.addEventListener(flash.events.MouseEvent.MOUSE_OUT, estPlusSurvolee);
			//this.addEventListener(flash.events.MouseEvent.DOUBLE_CLICK, estJouee);
			//this.addEventListener(flash.events.MouseEvent.CLICK, estCliquee);
			//this.addEventListener(flash.events.MouseEvent.MOUSE_DOWN, sourisAppuyee);
			//this.addEventListener(flash.events.MouseEvent.MOUSE_UP, sourisRelachee);
		}
			
			
		
	}
}